//package pub.wkq.api;
//
//import io.seata.core.context.RootContext;
//import io.seata.spring.annotation.GlobalTransactional;
//import io.seata.tm.api.GlobalTransaction;
//import io.seata.tm.api.GlobalTransactionContext;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.AfterThrowing;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//@Aspect
//public class SeataTransactionAspect {
//    /**
//     * 调用 service 方法之前开启全局事务
//     */
//    @Before("execution(* pub.wkq.*.service.impl..*.*(..))")
//    public void beginTransaction(JoinPoint joinPoint) throws Throwable {
//        //手动开启全局事务
//        GlobalTransaction gt = GlobalTransactionContext.getCurrentOrCreate();
//        gt.begin();
//    }
//
//    /**
//     * 捕获到异常，则手动回滚全局事务。
//     */
//    @AfterThrowing(
//            throwing = "throwable",
//            pointcut = "execution(* pub.wkq.*.service.impl..*.*(..))"
//    )
//    public void seataRollback(Throwable throwable) throws Throwable {
//        log.info("捕获到异常信息，则回滚，异常信息为：{}", throwable.getMessage() );
//        //从当前线程获取 XID，然后回滚
//        String xid = RootContext.getXID();
//        if (xid != null) {
//            GlobalTransactionContext.reload(xid).rollback();
//        }
//    }
//}
